package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.app.Advertising;
import com.ruoyi.system.domain.app.PowerBilling;
import com.ruoyi.system.domain.app.UserManual;
import com.ruoyi.system.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "通用相关")
@RestController
@RequestMapping
public class CommonsController extends BaseController {

    @Autowired
    CommonService commonService;

    @ApiOperation(value = "添加广告",notes = "system:ad:add")
    @PreAuthorize("@ss.hasPermi('system:ad:add')")
    @PostMapping("/ad/add")
    public AjaxResult addAd(@RequestBody Advertising advertising){
        commonService.addAd(advertising);
        return AjaxResult.success();
    }

    @ApiOperation(value = "删除广告",notes = "system:ad:del")
    @PreAuthorize("@ss.hasPermi('system:ad:del')")
    @DeleteMapping("/ad/del")
    public AjaxResult delAd(@RequestParam Long id){
        commonService.delAd(id);
        return AjaxResult.success();
    }

    @ApiOperation(value = "广告列表",notes = "system:ad:list'")
    @PreAuthorize("@ss.hasPermi('system:ad:list')")
    @GetMapping("/ad/list")
    public AjaxResult adList(){
        startPage();
        return AjaxResult.success(getDataTable(commonService.adList(new Advertising())));
    }

    @ApiOperation(value = "故障上报列表",notes = "system:feedback:list")
    @PreAuthorize("@ss.hasPermi('system:feedback:list')")
    @GetMapping("/feedback/list")
    public AjaxResult feedbackList(String userName,String phone,String deviceNum){
        startPage();
        return AjaxResult.success(getDataTable(commonService.feedbackList(userName,phone,deviceNum)));
    }

    @ApiOperation(value = "问题反馈列表",notes = "system:feedback:list")
    @PreAuthorize("@ss.hasPermi('system:feedback:list')")
    @GetMapping("/issue/feedback/list")
    public AjaxResult issueFeedbackList(String userName,String phone,String deviceNum){
        startPage();
        return AjaxResult.success(getDataTable(commonService.issueFeedbackList(userName,phone,deviceNum)));
    }

    @ApiOperation(value = "用户反馈解决",notes = "system:feedback:set")
    @PreAuthorize("@ss.hasPermi('system:feedback:set')")
    @PutMapping("/feedback/set")
    public AjaxResult feedbackSet(@RequestParam Long id){
        commonService.feedbackSet(id);
        return AjaxResult.success();
    }

    @ApiOperation(value = "获取用户协议",notes = "system:get:user:proto")
    @PreAuthorize("@ss.hasPermi('system:get:user:proto')")
    @PutMapping("/proto/get")
    public AjaxResult getProto(){
        return AjaxResult.success(commonService.getProto());
    }

    @ApiOperation(value = "重置用户协议",notes = "system:set:user:proto")
    @PreAuthorize("@ss.hasPermi('system:set:user:proto')")
    @PutMapping("/proto/set")
    public AjaxResult setProto(@RequestParam UserManual userManual){
        commonService.setProto(userManual);
        return AjaxResult.success();
    }

    @ApiOperation(value = "获取用户帮助",notes = "system:get:user:help")
    @PreAuthorize("@ss.hasPermi('system:get:user:help')")
    @PutMapping("/help/get")
    public AjaxResult getHelp(){
        return AjaxResult.success(commonService.getHelp());
    }

    @ApiOperation(value = "重置用户帮助",notes = "system:set:user:help")
    @PreAuthorize("@ss.hasPermi('system:set:user:help')")
    @PutMapping("/help/set")
    public AjaxResult setProto(@RequestParam List<UserManual> userManuals){
        commonService.setHelp(userManuals);
        return AjaxResult.success();
    }
}
